/*
 * @Author: Wilbur
 * @Date: 2019-03-21 18:21:28
 * @Last Modified by: Wilbur
 * @Last Modified time: 2019-03-21 18:44:38
 */
<template>
    <div class="container vip-set-wrap">
        <el-form
            v-if="init"
            ref="mainform"
            :model="formData"
            label-position="right"
            status-icon
            :rules="formRule"
            label-width="110px"
            :disabled="false">
            <!-- 权益设置 -->
            <div class="form-unit">
                <div class="form-title">会员设置</div>
                <el-form-item
                    class="task-form-item"
                    size="small"
                    prop="base_vip_count"
                    label="会员基础人数:">
                    <el-input
                        placeholder="必填"
                        v-model="formData.base_vip_count"
                        size="small"
                        type="number"
                        class="task-input"/>
                        <!-- <span style="display:inline-block;color:#999;margin-left:12px">*赞助商名称字数不超过15字</span> -->
                </el-form-item>
                <el-form-item
                    class="task-form-item"
                    size="small"
                    prop="intro"
                    label="会员说明:">
                    <el-input
                        placeholder="必填"
                        v-model="formData.intro"
                        size="small"
                        type="textarea"
                        :rows="5"
                        class="task-input"/>
                    <span style="display:inline-block;color:#999;margin-left:12px">*简介不超过500字</span>
                </el-form-item>
                <el-form-item
                    class="task-form-item"
                    size="small"
                    prop="price"
                    label="会员折价:">
                    <el-input
                        placeholder="必填"
                        v-model="formData.price"
                        size="small"
                        type="number"
                        class="task-input"/>
                        <!-- <span style="display:inline-block;color:#999;margin-left:12px">*标题字数不超过20字</span> -->
                </el-form-item>

                <el-form-item
                    class="task-form-item"
                    size="small"
                    prop="original_price"
                    label="会员原价:">
                    <el-input
                        placeholder="必填"
                        v-model="formData.original_price"
                        size="small"
                        type="number"
                        class="task-input"/>
                        <!-- <span style="display:inline-block;color:#999;margin-left:12px">*标题字数不超过20字</span> -->
                </el-form-item>
            </div>

            <div class="form-unit">
                <div class="operate-baar">
                    <el-button
                        size="medium"
                        @click="fnReset()">重置</el-button>
                    <el-button
                        size="medium"
                        type="primary"
                        @click="fnSubmit()">提交</el-button>
                </div>
            </div>
        </el-form>
    </div>
</template>

<script>
export default {
    components: { },
    data() {
        return {
            authResult: {},
            breadcrumbList: [
                {
                    title: "广告系统",
                },
                {
                    title: "账单日志",
                    name: 'checkList',
                },
                {
                    title: '会员设置'
                }
            ],
            formData: {
                base_vip_count: '',
                intro: '',
                price: '',
                original_price: ''
            },
            formRule: {
                base_vip_count: [
                    { required: true, message: '请输入会员基础人数', trigger: 'blur' }
                ],
                price: [
                    { required: true, message: '请输入会员价格', trigger: 'blur' }
                ],
                original_price: [
                    { required: true, message: '请输入会员原始价格', trigger: 'blur' }
                ],
                intro: [
                    { required: true, message: '请输入会员简介', trigger: 'blur' },
                    { min: 1, max: 500, message: '长度在 1 到 500 个字', trigger: 'blur' }
                ]
            },
            submitting: false,
            init: false,
            baseUrl: '',
            sessionTicket: localStorage.getItem('sessionTicket'),
            escape: escape
        };
    },
    created() {
        this.authResult = this.$route.meta.authResult;
        this.$store.commit('SET_HEADER', this.breadcrumbList);
        this.fnGetVipSet();
    },
    methods: {
        fnInitTimeNow() {
            var timestamp=new Date().getTime();

            return timestamp;
        },
        fnGetVipSet() {
            this.$post('/wei4/hire_user_vip%5Cget_config', {}, resp => {
                if(resp.code == 1){
                    this.formData = {
                        ...resp.data
                    };
                    this.init = true;
                }else{
                    this.$message({
                        type: 'warning',
                        message: resp.msg
                    });
                }
            });
        },
        fnSubmit(){
            if(this.submitting){
                return ;
            }
            this.$refs.mainform.validate(valid => {
                if(valid){
                    this.submitting = true;

                    let data = {
                        base_vip_count: this.formData.base_vip_count,
                        intro: this.formData.intro,
                        price: this.formData.price,
                        original_price: this.formData.original_price
                    };

                    this.$post('/wei4/hire_user_vip%5Cset_config', data, resp => {
                        if(resp.code == 1){
                            this.$message({
                                type: 'success',
                                center: true,
                                message: '操作成功'
                            });
                            this.$router.push({name: 'checkList'});
                        }else{
                            this.$message({
                                type: 'warning',
                                center: true,
                                message: resp.msg
                            });
                        }
                        this.submitting = false;
                    });
                }
            });
        },
        fnReset(){
            this.formData.base_vip_count = '';
            this.formData.intro = '';
            this.formData.price = '';
            this.formData.original_price = '';
        }
    },
};
</script>

<style lang="less" scoped>
    .margin-top{
        margin-top: 15px;
    }
    .vip-set-wrap {
      background: #fff;
      margin: 15px;
      margin-bottom: 0;
      padding: 30px;
      overflow: auto;
    }
    .form-unit {
      margin-bottom: 40px;
    }
    .form-title {
      font-size: 16px;
      font-weight: 600;
      color: rgba(0, 0, 0, 0.85);
      line-height: 18px;
      padding: 0 10px;
      border-left: 2px solid #1890ff;
      margin-bottom: 20px;
    }
    .task-input {
      width: 435px !important;
    }
    .operate-baar {
      width: 100%;
      text-align: center;
      margin-top: 168px;
    }
</style>
<style lang="less">
</style>
